package com.bwie.aliyun.config;

import com.bwie.aliyun.remote.RemotDocker;
import com.bwie.common.core.domain.Result;
import com.bwie.doctor.domain.po.MedRegistered;
import com.bwie.doctor.domain.vo.MedDoctorVo;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.List;
import java.util.function.Function;

@Configuration
public class AiConfig {
     @Autowired
     private RemotDocker remotDocker;

    //保存 聊天记录
    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }


    public record  CancelBookingRequest(String symptomName,Long doctorId,Long patientId,String realName,String patientName) {

    }

    //提取对话关键字  调用 function
    @Bean
    @Description("查找常见病医生")
    public Function<CancelBookingRequest, List<MedDoctorVo>> selectDocker() {
        return cancelBookingRequest -> {
            List<MedDoctorVo> medDoctorVos = remotDocker.queryDoctorList(cancelBookingRequest.symptomName);
            return medDoctorVos;
        };
    }

    @Bean
    @Description("取消挂号")
    public Function<CancelBookingRequest, String> cancelBooking() {
        return cancelBookingRequest -> {
            remotDocker.cancelDoctorState(cancelBookingRequest.realName,cancelBookingRequest.patientName);
            return "取消挂号成功";
        };
    }

    @Bean
    @Description("新增挂号")
    public Function<CancelBookingRequest, String> insertRegistered() {
        return cancelBookingRequest -> {
            remotDocker.registered(cancelBookingRequest.realName,cancelBookingRequest.patientName);
            return "挂号成功";
        };
    }
    @Bean
    @Description("查询挂号状态")
    public Function<CancelBookingRequest, MedRegistered> selectRegistered() {
        return cancelBookingRequest -> {
            Result<MedRegistered> medRegisteredResult = remotDocker.registerdFindByi(cancelBookingRequest.realName);
            MedRegistered medRegistered = medRegisteredResult.getData();
            return medRegistered;
        };
    }


}
